﻿using JetBrains.Annotations;
using System;
using Volo.Abp.UI.Navigation;

namespace Allin.Abp.AspNetCore.Components.Web.AntDesignTheme.Navigation
{
	public static class AntDesignThemeNavigationExtensions
	{
		public const string CustomDataComponentKey = "AntDesignTheme.CustomComponent";

		public static ApplicationMenuItem UseComponent(this ApplicationMenuItem applicationMenuItem, Type componentType)
		{
			return applicationMenuItem.WithCustomData(CustomDataComponentKey, componentType);
		}

		[CanBeNull]
		public static Type GetComponentTypeOrDefault(this ApplicationMenuItem applicationMenuItem)
		{
			if (applicationMenuItem.CustomData.TryGetValue(CustomDataComponentKey, out object componentType))
			{
				return componentType as Type;
			}

			return default;
		}
	}
}
